package com.aiyige.im.model.attachment;

import android.util.Log;

import com.aiyige.base.api.JsonUtil;
import com.aiyige.im.model.CustomMessageType;
import com.aiyige.im.model.CustomMsgData;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by xiachao
 */
public class UserAttachment extends CustomAttachment {

    private final String KEY_TYPE = "type";
    private final String KEY_DATA = "data";

    private int keyType;
    private CustomMsgData keyData;

    public UserAttachment() {
        super(CustomMessageType.user);
    }

    @Override
    protected void parseData(JSONObject data) {
        try {
            this.keyType = data.getInteger(KEY_TYPE);
            this.keyData = data.getObject(KEY_DATA, CustomMsgData.class);
        } catch (Exception e) {
            Log.e("parseData",e.toString());
        }

    }

    @Override
    protected JSONObject packData() {
        JSONObject data = null;
        try {
            data = JSONObject.parseObject(JsonUtil.toString(keyData));
        } catch (Exception e) {

        }
        return data;
    }


    public int getKeyType() {
        return keyType;
    }

    public CustomMsgData getKeyData() {
        return keyData;
    }

    public void setKeyType(int keyType) {
        this.keyType = keyType;
    }

    public void setKetData(CustomMsgData keyData) {
        this.keyData = keyData;
    }
}
